 <extend name="Base/common" />

<block name="style">
	<style>
		.logindiv{width: 60%;display: inline-block;margin-right: 1rem;float: left;}
		
	</style>
</block>

<block name="body">
<div class="alert alert-danger alert-dismissible fade in info" id="infodiv" hidden="hidden"  role="alert">
	<strong id="info"></strong>
</div>
<div class="hz-body">
	<form id="executeForm">
		<input type="hidden" name="aid" id="aid" value="{$aid}"/>
	  <div class="text-align-center">
	  	<h3>登录</h3>
	  </div>
	  <div class="form-group">
	    <input name="phone" type="text" id="phone" class="form-control"  placeholder="手机号码" onblur="check_phone()">
	  </div>
	  <div class="form-group">
	    <input name="password" type="password" id="password" class="form-control" placeholder="密码" onblur="check_password()">
	  </div>
	  <div style="overflow: auto;">
		  <div class="logindiv">
		  	<button type="button" id="login-btn" class="btn btn-primary wid70 fr">登录</button>
		  </div>
		  <div style="width: 30%;float: left;margin-top: 14px;">
		  	<a href="{:U('User/register')}" style="font-size: 0.8rem;">注册</a>
		  </div>
	  </div>
	  <div id="" style="margin-top: 12px;">
	  	<div class="logindiv" style="height: 1px;"> </div>
	  	<a href="{:U('User/reset_pwd')}" style="font-size: 0.8rem;">忘记密码</a>
	  </div>
	</form>
</div>
</block>
<block name="script">
	<script src="__JS__/User/check.js"></script>
	<script>
        get_cookie();
        function get_cookie() {
            $.post("{:U('User/get_cookie')}", function(res) {
                $("#phone").val(res.phone);
                $("#password").val(res.password);
            });
        }
        $('#login-btn').on('click', post);
        function post() {
            var $this = $('#login-btn'), ph = check_phone(), p = check_password();
            if (!ph) {
                $('#phone').focus();
            } else if (!p) {
                $('#password').focus();
            } else {
                $this.text('登录中...').off('click');
                $.post("{:U('User/login')}",$('#executeForm').serialize(), function(res) {
                    if (res.status) {
                        location.href = res.url;
                    } else {
                    	$('#info').html(res.info);
                        $('#infodiv').show();
                        $this.text('登录').on('click', post);
                        setTimeout("$('#infodiv').hide()",3000);
                    }
                });
            }
        }
        $('#infodiv').click(function(){$('#infodiv').hide();});
        function check_phone() {
            var pi = $('#phone'), p = pi.val();
            if (!/^1[3|4|5|7|8][0-9]\d{8}$/.test(p)) {
                pi.css('border', '1px solid red').prev().children('span').html('手机号码不正确');
                return false;
            } else {
                pi.css('border', '1px solid #a9a9a9').prev().children('span').html('');
                return true;
            }
        }
        function check_password() {
            var pi = $('#password'), p = pi.val().trim();
            if (!p) {
                pi.css('border', '1px solid red').val('').prev().children('span').html('请输入密码');
                return false;
            } else {
                pi.css('border', '1px solid #a9a9a9').prev().children('span').html('');
                return true;
            }
        }
        $(document).ready(function(){
			$("#login_li").addClass("active");//左边的菜单栏亮起来
		});
    </script>
</block>